#include "widget.h"
#include "ui_widget.h"
#include<QDir>
#include <QTextStream>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    this->setGeometry(300,200,1000,600);
    combox=new QComboBox(this);
    combox->setGeometry(10,10,200,30);
    combox->addItem("北京市");
    combox->addItem("上海市");
    combox->addItem("天津市");
    combox->addItem("重庆市");
    combox->addItem("湖南省");
    combox->addItem("江西省");
    combox->addItem("广东省");
    combox->addItem("香港特别行政区");
    combox->addItem("澳门特别行政区");


    connect(combox,&QComboBox::currentTextChanged,this,&Widget::comboxSlot);


    qfontCombox=new QFontComboBox(this);
    label=new QLabel(this);
    label->setGeometry(10,70,300,50);
    qfontCombox->setGeometry(10,50,200,30);

    connect(qfontCombox,&QFontComboBox::currentFontChanged,this,&Widget::showlabels);

    lineedit=new QLineEdit(this);
    btn1=new QPushButton(this);
    btn1->setText("点击我");

    lineedit->setGeometry(10,150,300,30);
    btn1->setGeometry(320,150,100,30);

    label1=new QLabel(this);
    label1->setGeometry(10,190,300,30);

    connect(btn1,&QPushButton::clicked,this,&Widget::clickBtnSlot);

    //4.
    palintext=new QPlainTextEdit(this);
    palintext->setGeometry(10,250,400,200);
    radiobtn=new QRadioButton(this);
    radiobtn->setGeometry(300,220,200,30);
    radiobtn->setText("只读模式");


    QFile fe("D:/job/qt/work/me/day1/MyInputWidget/csdn2.txt");
    fe.open((QFile::ReadOnly|QFile::Text));

    //加载文件流
    QTextStream strin(&fe);
    qDebug()<<strin.readAll();
    //将文件指针移到开头
    fe.seek(0);
    palintext->insertPlainText(strin.readAll());
    connect(radiobtn,&QRadioButton::clicked,this,&Widget::radiobtnslot);

    //5.改变窗口的颜色
    this->setStyleSheet("Widget{background-color:rgba(250,250,0);}");

    spinbox=new QSpinBox(this);
    spinbox->setGeometry(440,250,150,30);

    spinbox->setRange(0,100);
    spinbox->setSingleStep(10);
    spinbox->setValue(100);

    spinbox->setSuffix("%不透明度");

    void ( QSpinBox::*pt1)(int)=&QSpinBox::valueChanged;

    connect(spinbox,pt1,this,&Widget::spinboxValueChanged);

    //6.日期时间类
    dt1=new QDateTimeEdit(QDateTime::currentDateTime(),this);
    dt1->setGeometry(440,290,200,30);
    tm=new QTimeEdit(QTime::currentTime(),this);
    tm->setGeometry(440,330,200,30);
    dt2=new QDateEdit(QDate::currentDate(),this);
    dt2->setGeometry(440,370,200,30);

    //7.
    hscrollbar=new QScrollBar(Qt::Horizontal,this);
    hscrollbar->setGeometry(0,500,1000,30);
    vscrollbar=new QScrollBar(Qt::Vertical,this);
    vscrollbar->setGeometry(970,0,30,500);


}

Widget::~Widget()
{
    delete ui;
}

void Widget::comboxSlot(const QString &text)
{
    QMessageBox::information(this,"信息",text,QMessageBox::Yes,QMessageBox::No);
}

void Widget::showlabels(const QFont &font)
{
    label->setText("你好棒，张仪如");
    label->setFont(font);
}

void Widget::clickBtnSlot()
{
   QString str= lineedit->text();
   label1->setText("你输入的内容为: "+str);
}

void Widget::radiobtnslot(bool checked)
{
    if(radiobtn->isChecked()){
        palintext->setReadOnly(true);
    }
    else
        palintext->setReadOnly(false);
}

void Widget::spinboxValueChanged(int x)
{
    double dx=(double)x/100;
    this->setWindowOpacity(dx);
}

void Widget::keyseqeditChanged(const QKeySequence &)
{

}

